[#include "/includes/_layout.html"/]
<title>添加手机流量包</title>
<script type="text/javascript">
var prizeId = '${prize.id }';
$(document).ready(function() {
	//保存奖品
	$("#savePrize").click(function(){
		var params = {}, error = {};	
		var prize_single_cash = $("#prize_single_cash").val();//单个流量包有多少M
		var publish_count = $("#publish_count").val();//总流量包个数
		var prizeId = $("#id").val(), prize_type_id = $("#prize_type_id").val(), 
		prizeName = $("#prize_name").val(), prize_img = $("#prize_img").val(),
		prize_memo = $("#prize_memo").val(), prize_price = $("#prize_price").val(),
		startDate = $("#start_date").val(), endDate = $("#end_date").val();
		if(prizeId!=null && prizeId!="") params.id = prizeId;
		if(prize_memo!=null && prize_memo!="") params.prize_memo = prize_memo;
		if(prize_img !=null && prize_img !="") params.prize_img=prize_img;
		params.prize_type_id = prize_type_id;
		if($.trim(prizeName) =="") {error.error_prize_name = "奖品名称不能为空"; } else {error.error_prize_name=""; params.prize_name = $.trim(prizeName);}
		if($.trim(prize_single_cash) =="") {error.error_prize_single_cash = "单份奖品手机流量数量不能为空"; } else {error.error_prize_single_cash=""; params.prize_single_cash = $.trim(prize_single_cash);}
		if($.trim(publish_count) =="") {error.error_publish_count = "奖品数量不能为空"; } else {error.error_publish_count =""; params.publish_count = $.trim(publish_count);}
		if($.trim(prize_price) =="") {error.error_prize_price = "奖品价值不能为空"; } else {error.error_prize_price =""; params.prize_price = $.trim(prize_price);}
		/* if($.trim(startDate) =="") {error.error_start_date = "有效开始时间不能为空"; } else {error.error_start_date =""; params.start_date = $.trim(startDate);}
		if($.trim(endDate) =="") {error.error_end_date = "有效结束时间不能为空"; } else { error.error_end_date=""; params.end_date = $.trim(endDate);} */
		
		var hasError = false;
		for(var key in error){
			if(error[key]!=""){
				if(!hasError) hasError = true;
				$("#"+key).addClass("has-error");
    			$("#"+key).find("label").text(error[key]);
			}else{
				$("#"+key).removeClass("has-error");
				$("#"+key).find("label").empty();
			}
		}
		//主表信息不完整，返回
		if(hasError) return false;
		
		
		var money = prize_single_cash * publish_count * 0.12;
		if(money<=0){
			obz.showMessage("亲，流量花费人民币为0，请检查流量设置");
			return false;
		}
		obz.showMessage("此次流量总共值人民币:<font color='red'>" + money + "</font>元，软件自动发放流量到中奖买家的手机账号，确定保存吗？", function (){
			$("#container").mask("正在保存...");
			obz.ajaxJson (obz.ctx+"/prize/save", $("#prizeForm").serialize(), function(data){
				$("#container").unmask();
				var response = data;
				if(data.code!=200){
					obz.showMessage(response.msg);
				}else{
					if(addPrizeDailog != null) addPrizeDailog.close();
					searchPrizes();
				}
			},function(){
				$("#container").unmask();
				$("[id^='error_']").each(function(){
					$(this).removeClass("has-error");
					$(this).find("label").empty();
				}); 
			});
		});
	});	
});
</script>
</head>
<body class="fixed-sidebar full-height-layout gray-bg">
<div class="panel-body">
	<div class="alert alert-success">
		<strong>提示:</strong> 手机流量包由系统自动发放，用户获得后系统将立即发奖，无需手工操作！.
	</div>
	
	<form name="prizeForm" id="prizeForm" action="" method="post" class="form-horizontal ">
		<input type="hidden" name="prize_type_id" id="prize_type_id" value="${prizeTypeId }"/>
		<input type="hidden" name="active" id="active" value="${prize.active }"/><!-- 默认为1，值为0的时候表示删除，删除后用户不可见 -->
		<input type="hidden" name="id" id="id" value="${prize.id }"/>
        <div class="form-group">
            <label class="col-md-2 control-label">奖品名称<span style="color: red;"><em>*</em></span></label>
            <div class="col-md-5" id="error_prize_name">
                <input type="text" id="prize_name" name="prize_name" value="${prize.prizeName }" class="form-control" placeholder="比如10M流量免费送">
                <label class="control-label" for="prize_name"></label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-md-2 control-label">奖品数量<span style="color: red"><em>*</em></span></label>
            <div class="col-md-5" id="error_publish_count">
                <input type="text" id="publish_count" name="publish_count" value="${prize.publishCount }" class="form-control" placeholder="比如填写100" onkeyup="value=value.replace(/[^\d]/g,'')">
                <label class="control-label" for="publish_count"></label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-md-2 control-label">单份奖品手机流量数量（M）<span style="color: red;"><em>*</em></span></label>
            <div class="col-md-5" id="error_prize_single_cash">
                <input type="text" id="prize_single_cash" name="prize_single_cash" value="${prize.prizeSingleCash }" class="form-control" placeholder="比如填写10">
                <label class="control-label" for="prize_single_cash"></label>
            </div>
            <span class="alert-success">
            	<i class="fa fa-info-circle"></i>比如填10的话，获得一份奖品，就是获得10M手机流量
            </span>
        </div>
        <div class="form-group">
            <label class="col-md-2 control-label">奖品价值（元）<span style="color: red"><em>*</em></span></label>
            <div class="col-md-5" id="error_prize_price">
                <input type="text" id="prize_price" name="prize_price" value="${prize.prizePrice }" class="form-control" placeholder="比如填写100" onkeyup="value=value.replace(/[^\d]/g,'')">
                <label class="control-label" for="prize_price"></label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-md-2 control-label">图片</label>
            <div class="col-md-5" id="error_prize_img">
                <input type="text" id="prize_img" name="prize_img" value="${prize.prizeImg }" class="form-control" placeholder="请复制淘宝图片空间图片链接地址">
                <div class="alert-success">
	              <span><i class="fa fa-info-circle"></i>请到淘宝<a class="blue" href="http://tadget.taobao.com/redaction/manager.htm" target="_blank">图片空间</a>选择图片，再复制链接到此处。</span>
	            </div>
                <label class="control-label" for="prize_img"></label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-lg-2 col-md-2 col-sm-12 control-label">有效时间</label>
            <div class="col-lg-10 col-md-10">
                <div class="row">
                    <div class="col-lg-3 col-md-3">
                        <input type="text" id="start_date" name="start_date" style="width: 160px; cursor: pointer;" readonly="readonly"
						onfocus="WdatePicker({isShowClear:false,readOnly:true,dateFmt:'yyyy-MM-dd',minDate:'%y-%M-%d %H:%m:%s',maxDate:'#F{$dp.$D(\'end_date\')}'})"
						class="Wdate" value="${prize.startDate }" />
                    </div>
                    <div class="col-lg-3 col-md-3">
                        <input type="text" id="end_date" name="end_date" style="width: 160px; cursor: pointer;" readonly="readonly"
						onfocus="WdatePicker({isShowClear:false,readOnly:true,dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'start_date\',{d:28, H:23, m:59, s:59});}'})"
						class="Wdate" value="${prize.endDate }" />	
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-md-2 control-label">领取说明</label>
            <div class="col-md-5">
                <textarea id="prize_memo" name="prize_memo" rows="3" class="form-control" placeholder="">${prize.prizeMemo }</textarea>
            </div>
        </div>
    </form>
</div>
<div class="panel-footer" align="center">
    <button id="savePrize" class="btn btn-sm btn-success"><i class="fa fa-dot-circle-o"></i>提交</button>
</div>
</body>
</html>